define(function () {
	

    $.wjtBaseFront = "/node5/#";
    $.wjtBaseBackend = "/node4";
    $.wjtBaseCdn = "http://qiniucdn.haojs.com.cn/";
    $.qiniuBase = "/qiniucdn"
    
    $.const = {
        "defaultAvatar": $.wjtBaseCdn + "default.jpg"
    };

	$.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");  
        var r = window.location.search.substr(1).match(reg);  
        if (r != null) return unescape(r[2]);  
        return null;  
    };

    $.getHashUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");  
		var temp_i = window.location.hash.indexOf("?");
        if(temp_i == -1){
        	return null;
        }else{
	        var r = window.location.hash.substr(temp_i + 1).match(reg);  
	        if (r != null) return unescape(r[2]);  
	        return null;  
        }

    };

    $.isTel = function(str){
      var reg = /^[0-9]*\d{11}$/;
      return reg.test(str);  
    },
    $.isNullStr = function(val){
        return (val == null || typeof(val) == "undefined" || val.length == 0);
    }
    $.isNull = function(val){
        return (val == null || typeof(val) == "undefined");
    };

    $.redirectTo = function(url){
        if($.isNull(url))
            return;
        location.href=url;
    };

    $.refreshPage = function(url){
        location.reload();
    }

    $.processing = function (str, s, callback_Func){
        $.showPreloader(str);
        setTimeout(callback_Func, s);
    };

    $.promptMobleMsgCode = function (text, title, callbackOk, callbackCancel) {
        if (typeof title === 'function') {
            callbackCancel = arguments[2];
            callbackOk = arguments[1];
            title = undefined;
        }
        return $.modal({
            text: text || '',
            afterText: '<input type="tel" class="modal-text-input" style="text-align: center;font-size: 2rem;height: 2.2rem;">',
            buttons: [
                {
                    text: "确定",
                    close: false,
                    bold: true
                }
            ],
            onClick: function (modal, index) {
                if (index === 0 && callbackOk) callbackOk($(modal).find('.modal-text-input').val());
            }
        });
    };


    $.promptInput = function (text,value, callbackOk, callbackCancel,type , style) {

        return $.modal({
            text: text || '',
            afterText: '<input type="'+type+'" class="modal-text-input" style="'+style+'" value="'+value+'">',
            buttons: [
                
                {
                    text: "取消",
                    close: true,
                    bold: true
                },
                {
                    text: "确定",
                    close: true,
                    bold: true
                }
            ],
            onClick: function (modal, index) {
                if (index === 0 && callbackCancel) callbackCancel($(modal).find('.modal-text-input').val());
                if (index === 1 && callbackOk) callbackOk($(modal).find('.modal-text-input').val());
                
            }
        });
    };

    $.promptTextArea = function (text,value, callbackOk, callbackCancel,style) {

        return $.modal({
            text: text || '',
            afterText: '<textarea class="modal-text-input" style="'+style+'" >'+value+'</textarea>',
            buttons: [
                
                {
                    text: "取消",
                    close: true,
                    bold: true
                },
                {
                    text: "确定",
                    close: true,
                    bold: true
                }
            ],
            onClick: function (modal, index) {
                if (index === 0 && callbackCancel) callbackCancel($(modal).find('.modal-text-input').val());
                if (index === 1 && callbackOk) callbackOk($(modal).find('.modal-text-input').val());
                
            }
        });
    };

    $.promptHelpAssistant = function (text) {

        $.modal({
          title:  '扫描下方二维码寻求帮助',
          text: '<img src="http://qiniucdn.haojs.com.cn/Hjs2016qrcode.jpg" style="width: 60%;"><p style="font-size: 12px;">'+text+'</p>',
          verticalButtons: true,
          buttons: [
            {
              text: '关闭',
              close: true
            }
          ]
        })

    };


    $.promptPptUpload = function (id) {

        $.modal({
          title:  '点击下方按钮上传PPT',
          text: '<div><button id="'+id+'" style="width:100%" class="button button-fill button-big">+</button></div><div><p style="font-size: 14px;color: red;">支持格式：pptx，ppt，pdf</p></div>',
          verticalButtons: true,
          buttons: [
            {
              text: '关闭',
              close: true
            }
          ]
        })

    };


    $.timeFormat = function(timestamp){

        function add0(m){return m<10?'0'+m:m }
        var time = new Date(timestamp);
        var y = time.getFullYear();
        var m = time.getMonth()+1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm);//+':'+add0(s);

    }

    $.genModalButton = function(val, callback_Func, opt){

        var button = {};

        button.text = val;
        button.onClick = callback_Func;

        button.opt = opt;
        return button;
     }


    $.geCloseModalButton = function(val){

        var button = {};

        button.text = '<span style="color:red;">'+val+'</span>';
        button.close = true;
        button.bold = true;

        return button;
     }

    $.promptMoreOperation = function (ops) {
        ops.push($.geCloseModalButton("关闭菜单"));
        $.modal({
          text:  '操作选项',
          verticalButtons: true,
          buttons: ops
        });
    }

    $.promptProgressSetup = function(title, total){

        var content = 
            '<div class="progress-uploading progress-info">'+
                '<div class="progress progress-striped">'+
                    '<div class="progress-bar progress-bar-info" role="progressbar" style="width: 0%;">'+
                        '<span class="sr-only"></span>'+
                    '</div>'+
                '</div>'+
                '<div class="status text-left">已上传: <span class="valuenow">0 MB</span> / <span class="valuemax">'+total+'</span> <br>上传速度： <span class="speed"></span>/S</div>'+
            '</div>';


        $.modal({
          title: title,
          text: content
        })
    }

    $.promptProgressUpdate = function(percent, speed, valuenow){

        var progress = $(".progress-uploading");
        progress.find(".progress-bar").css("width",percent);
        progress.find(".speed").html(speed);
        progress.find(".valuenow").html(valuenow);
    }

    $.promptConvertProgressSetup =  function(title, text){

        var content = 
            '<div class="progress-convert progress-info">'+
                '<div class="progress progress-striped">'+
                    '<div class="progress-bar progress-bar-info" role="progressbar" style="width: 0%;">'+
                        '<span class="sr-only"></span>'+
                    '</div>'+
                '</div>'+
               '<div class="status text-left">'+text+'</div>'+
            '</div>';


        $.modal({
          title: title,
          text: content
        })
    }

    $.promptConvertProgressUpdate = function(percent, title, text){

        $(".modal-title").html(title);
        var progress = $(".progress-convert");
        progress.find(".progress-bar").css("width",percent);
        progress.find(".status").html(text);
    }

    $.promptAddResource = function (callbackOk, callbackCancel) {

        return $.modal({
            title:'是否使用电脑浏览器上传PPT',
            // text: '请通过电脑访问<br><a href="javascript:void(0)">http://www.haojs.com.cn/ppt.do</a>',
            text: '请通过电脑访问<br><a href="javascript:void(0)">http://www.haojs.com.cn/node5/#/pc_login</a>',

            buttons: [
                
                {
                    text: "不使用",
                    close: true,
                    bold: true
                },
                {
                    text: "使用",
                    close: true,
                    bold: true
                }
            ],
            onClick: function (modal, index) {
                if (index === 0 && callbackCancel) callbackCancel($(modal).find('.modal-text-input').val());
                if (index === 1 && callbackOk) callbackOk($(modal).find('.modal-text-input').val());
                
            }
        });
    }
    
    
    $.promptTubeUpload = function (id,pageurl,callback) {
    	
    	var text = 
    	'<div>'+
    	'  <div style="font-size:10px;text-align:left;">'+
    	 ' 参考URL：<br>'+
    	  '<b>Youku:</b><br>'+
    	   'http://player.youku.com/embed/XMTMzOTE4NDY1Ng==<br>'+
    	    '<b>Iqiyi:</b><br>'+
    	    'http://open.iqiyi.com/developer/player_js/coopPlayerIndex.html?vid=750b4954c7c56fc4ec7de12f0fa6e69e&amp;tvId=4819571709&amp;accessToken=2.f22860a2479ad60d8da7697274de9346&amp;appKey=3955c3425820435e86d0f4cdfe56f5e7&amp;appId=1368&amp;height=100%&amp;width=100%<br>'+
    	  '</div>'+
    	'<input class="modal-text-input" id="'+id+'" value="'+pageurl+'" style="width:100%;">'+
    	'</div>';
        $.modal({
          title:  '设置Tube链接',
          text: text,
          verticalButtons: true,
          buttons: [
            {
              text: '确定',
              close: true
            }
          ],
          onClick: function (modal, index) {
              if (index === 0 && callback) callback($(modal).find('.modal-text-input').val());
          }
        })

    };
    
    
});
